import { ref, computed } from 'vue'
import { defineStore } from 'pinia'
import { fromDateStr } from '@/utils/utils';

export const useMonitor = defineStore('monitor', () => {
    const checked = ref(false);
    const values = ref<{ level: string, nick: string, text: string, status: string, time: string }[]>([]);

    const logs = ref<string[]>([]);
    const list = computed(() => {
        if (values.value.length < 11) {
            return [...values.value, ... new Array(11 - values.value.length).join('|').split('|').map(() => {
                return {
                    level: '', nick: '', text: ''
                }
            })]
        }
        return values.value;
    });

    const add = (opts: { level: string, nick: string, text: string, status: string, time: string }) => {
        values.value.unshift(opts);
    }

    const log = (str: string) => {
        
        logs.value.unshift(`${fromDateStr(Date.now())}:${str}`);
    }

    return { list, values, checked, add, logs, log }
});


